﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BB.Apostas.Models;
using BB.Apostas.Filters;

namespace BB.Apostas.Controllers
{
    [InitializeSimpleMembership]
    public class HomeController : Controller
    {
        private ApostasBalasDbContext db = new ApostasBalasDbContext();

        public ActionResult Index()
        {
            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";

            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }

        [ChildActionOnly]
        public ActionResult GetNoticia()
        {
            return PartialView("_NoticiaPartial", db.Noticias.OrderByDescending(n => n.Id).FirstOrDefault());
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Submit(Reporte report)
        {
            if (ModelState.IsValid)
            {
                db.Reportes.Add(report);
                db.SaveChanges();
                ViewData["Success"] = report.ReportType + " enviado com sucesso.";
                return View("Contact");
            }
            return View("Contact");
        }
    }
}
